package com.betterjr.modules.application.entity;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.Access;
import javax.persistence.AccessType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Transient;

import com.betterjr.common.annotation.MetaData;
import com.betterjr.common.entity.BetterjrEntity;
import com.betterjr.common.selectkey.SerialGenerator;
import com.betterjr.common.utils.BTAssert;
import com.betterjr.common.utils.BetterDateUtils;
import com.betterjr.modules.account.entity.CustOperatorInfo;
import com.betterjr.modules.application.data.ApplicationGroupConstantCollections;

/**
 * 
 * @ClassName: ApplicationGroup 
 * @Description: t_ams_applicationgroup 应用分组表
 * @author xuyp
 * @date 2017年11月17日 下午6:04:02 
 *
 */
@Access(AccessType.FIELD)
@Entity
@Table(name = "t_ams_applicationgroup")
public class ApplicationGroup implements BetterjrEntity {

    /** 
     * @Fields serialVersionUID : 
     */
    private static final long serialVersionUID = -9166659823494736003L;

    /**
     * 流水号
     */
    @Id
    @Column(name = "ID", columnDefinition = "INTEGER")
    @MetaData(value = "流水号", comments = "流水号")
    private Long id;

    /**
     * 应用名称
     */
    @Column(name = "C_APPLICATIONGROUP_NAME", columnDefinition = "VARCHAR")
    @MetaData(value = "应用名称", comments = "应用名称")
    private String applicationGroupName;

    /**
     * 状态 1 正常   9 删除
     */
    @Column(name = "C_BUSINSTATUS", columnDefinition = "VARCHAR")
    @MetaData(value = "状态 1 正常   9 删除", comments = "状态 1 正常   9 删除")
    private String businStatus;

    /**
     * 注册日期
     */
    @Column(name = "C_REG_DATE", columnDefinition = "VARCHAR")
    @MetaData(value = "注册日期", comments = "注册日期")
    private String regDate;

    /**
     * 日期时间
     */
    @Column(name = "C_REG_TIME", columnDefinition = "VARCHAR")
    @MetaData(value = "日期时间", comments = "日期时间")
    private String regTime;

    /**
     * 注册操作员
     */
    @Column(name = "L_REG_OPERATORID", columnDefinition = "INTEGER")
    @MetaData(value = "注册操作员", comments = "注册操作员")
    private Long regOperatorId;

    /**
     * 注册操作员名称
     */
    @Column(name = "C_REG_OPERATORNAME", columnDefinition = "VARCHAR")
    @MetaData(value = "注册操作员名称", comments = "注册操作员名称")
    private String regOperatorName;

    /**
     * 当前分组总的数量
     */
    @Transient
    private Integer appliationCount;

    /**
     * 当前分组所有的应用信息
     */
    @Transient
    private List<Application> applicationList = new ArrayList<>();

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getApplicationGroupName() {
        return applicationGroupName;
    }

    public void setApplicationGroupName(String applicationGroupName) {
        this.applicationGroupName = applicationGroupName;
    }

    public String getBusinStatus() {
        return businStatus;
    }

    public void setBusinStatus(String businStatus) {
        this.businStatus = businStatus;
    }

    public String getRegDate() {
        return regDate;
    }

    public void setRegDate(String regDate) {
        this.regDate = regDate;
    }

    public String getRegTime() {
        return regTime;
    }

    public void setRegTime(String regTime) {
        this.regTime = regTime;
    }

    public Long getRegOperatorId() {
        return regOperatorId;
    }

    public void setRegOperatorId(Long regOperatorId) {
        this.regOperatorId = regOperatorId;
    }

    public String getRegOperatorName() {
        return regOperatorName;
    }

    public void setRegOperatorName(String regOperatorName) {
        this.regOperatorName = regOperatorName;
    }

    public Integer getAppliationCount() {
        return appliationCount;
    }

    public void setAppliationCount(Integer appliationCount) {
        this.appliationCount = appliationCount;
    }

    public List<Application> getApplicationList() {
        return applicationList;
    }

    public void setApplicationList(List<Application> applicationList) {
        this.applicationList = applicationList;
    }

    @Override
    public String toString() {
        return "ApplicationGroup [id=" + id + ", applicationGroupName=" + applicationGroupName + ", businStatus="
                + businStatus + ", regDate=" + regDate + ", regTime=" + regTime + ", regOperatorId=" + regOperatorId
                + ", regOperatorName=" + regOperatorName + "]";
    }

    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result + ((applicationGroupName == null) ? 0 : applicationGroupName.hashCode());
        result = prime * result + ((businStatus == null) ? 0 : businStatus.hashCode());
        result = prime * result + ((id == null) ? 0 : id.hashCode());
        result = prime * result + ((regDate == null) ? 0 : regDate.hashCode());
        result = prime * result + ((regOperatorId == null) ? 0 : regOperatorId.hashCode());
        result = prime * result + ((regOperatorName == null) ? 0 : regOperatorName.hashCode());
        result = prime * result + ((regTime == null) ? 0 : regTime.hashCode());
        return result;
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj) return true;
        if (obj == null) return false;
        if (getClass() != obj.getClass()) return false;
        ApplicationGroup other = (ApplicationGroup) obj;
        if (applicationGroupName == null) {
            if (other.applicationGroupName != null) return false;
        } else if (!applicationGroupName.equals(other.applicationGroupName)) return false;
        if (businStatus == null) {
            if (other.businStatus != null) return false;
        } else if (!businStatus.equals(other.businStatus)) return false;
        if (id == null) {
            if (other.id != null) return false;
        } else if (!id.equals(other.id)) return false;
        if (regDate == null) {
            if (other.regDate != null) return false;
        } else if (!regDate.equals(other.regDate)) return false;
        if (regOperatorId == null) {
            if (other.regOperatorId != null) return false;
        } else if (!regOperatorId.equals(other.regOperatorId)) return false;
        if (regOperatorName == null) {
            if (other.regOperatorName != null) return false;
        } else if (!regOperatorName.equals(other.regOperatorName)) return false;
        if (regTime == null) {
            if (other.regTime != null) return false;
        } else if (!regTime.equals(other.regTime)) return false;
        return true;
    }

    /**
     * 
     * @Title: saveModifyValue 
     * @Description: 新增或者修改应用初始化值
     * @param operatorInfo
     * @param anFlag 1：新增应用分组   2修改应用分组
     * @throws 
     * @author xuyp
     * @date 2017年11月15日 下午3:05:04
     */
    public void saveModifyValue(CustOperatorInfo operatorInfo, String anFlag) {

        BTAssert.notNull(operatorInfo, "请先登录,操作失败");
        if ("1".equals(anFlag)) {
            // 新增需要添加id
            this.setId(SerialGenerator.getLongValue("ApplicationGroup.id"));
            this.setBusinStatus(ApplicationGroupConstantCollections.APPLICATIONGROUP_BUSINSTATUS_OK);
        }

        this.setRegDate(BetterDateUtils.getNumDate());
        this.setRegOperatorId(operatorInfo.getId());
        this.setRegOperatorName(operatorInfo.getName());
        this.setRegTime(BetterDateUtils.getNumTime());

    }

}
